package com.fire.eyes.service.impl;

import java.util.concurrent.TimeUnit;

import com.fire.eyes.dao.TMitServiceDicBaseMapper;
import com.fire.eyes.model.TMitServiceDicBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.fire.eyes.service.ITMitServiceDicBaseService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

/**
 * <p>
 * 基础字典表 服务实现类
 * </p>
 *
 * @author MIT123
 * @since 2018-04-26
 */
@Service
public class TMitServiceDicBaseServiceImpl extends ServiceImpl<TMitServiceDicBaseMapper, TMitServiceDicBase>
        implements ITMitServiceDicBaseService {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * @param token
     * @return
     * @throws Exception
     */
    @Override
    public boolean ckeckToken(String token) throws Exception {
        boolean flag = false;
        // 验证token是否超时
        Long oldDate = redisTemplate.getExpire(token, TimeUnit.MINUTES);
        if (oldDate > 0) {
            String oldoken = (String) redisTemplate.opsForValue().get(token);
            if (token.equals(oldoken)) {
                flag = true;
            }
        } else {
            redisTemplate.delete(token);
        }

        return flag;
    }

}
